<template>
  <div class="drawer-box">
    <div class="tips">基础信息</div>
    <div class="infomation-box">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="项目名称" :span="2">{{ asInfo.xm_project_name }}</el-descriptions-item>
        <el-descriptions-item label="项目编号">{{ asInfo.xm_project_number }}</el-descriptions-item>
        <el-descriptions-item label="项目客户经理">{{ asInfo.xm_account_manager_name }}</el-descriptions-item>
        <el-descriptions-item label="项目工程经理">{{ asInfo.xm_engineering_manager_name }}</el-descriptions-item>
        <el-descriptions-item label="项目工程监理">{{ asInfo.xm_engineering_supervision_name }}</el-descriptions-item>
        <el-descriptions-item label="结算完成日期">{{ asInfo.xm_settlement_completion_date }}</el-descriptions-item>
        <el-descriptions-item label="质保截止日期">{{ asInfo.xm_warranty_deadline_date }}</el-descriptions-item>
        <el-descriptions-item label="是否质保期">{{ asInfo.is_sell_by == 1 ? '是' : '否' }}</el-descriptions-item>
        <el-descriptions-item label="发起人">{{ asInfo.user_name }}</el-descriptions-item>
        <el-descriptions-item label="售后工程经理">{{ asInfo.engineering_manager_name }}</el-descriptions-item>
        <el-descriptions-item label="售后工程监理">{{ asInfo.engineering_supervision_name }}</el-descriptions-item>
        <el-descriptions-item label="内容描述" :span="2">{{ asInfo.problem_content }}</el-descriptions-item>
        <el-descriptions-item label="附件" :span="2">
          <span class="theme-color underline span-file" v-for="(item, idx) in asInfo.after_sales_file" :key="idx"
            @click="$fileViewHandle(item)">{{ item.file_name }}</span>
          <span v-if="asInfo.after_sales_file && asInfo.after_sales_file.length == 0">--</span>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <div class="tips">操作历史</div>
    <div class="oper-history-box">
      <el-timeline class="timeline" :reverse="false">
        <el-timeline-item v-for="(item, idx) in asInfo.log_list" :key="idx">
          <div class="setp-box">
            <div class="setp-top flex ac jb">
              <p class="time">{{ item.created_at }}</p>
              <div class="user-box flex ac">
                <img class="avater" :src="item.handlers_image" />
                {{ item.handlers_name }}-{{ item.handlers_position }}
              </div>
            </div>
            <div class="setp-content" v-if="item.after_sales_status == 20">
              <div class="title">{{ item.content }}</div>
              <el-descriptions :column="2">
                <el-descriptions-item label="工程监理" :span="2">{{ asInfo.engineering_supervision_name
                  }}</el-descriptions-item>
                <el-descriptions-item label="内容描述" :span="2">{{ asInfo.problem_content }}</el-descriptions-item>
                <el-descriptions-item label="附件" :span="2">
                  <template v-for="(item2, idx) in asInfo.after_sales_file">
                    <span class="theme-color underline span-file" :key="idx" @click="$fileViewHandle(item2)">
                      {{ item2.file_name }}
                    </span>
                  </template>
                  <span v-if="asInfo.after_sales_file.length == 0">--</span>
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="setp-content" v-if="item.after_sales_status == 30">
              <div class="title">{{ item.content }}</div>

              <el-descriptions :column="2" v-if="asInfo.user_position == '工程监理'">
                <el-descriptions-item label="工程经理" :span="2">{{ asInfo.engineering_manager_name
                  }}</el-descriptions-item>
                <el-descriptions-item label="内容描述" :span="2">{{ asInfo.problem_content }}</el-descriptions-item>
                <el-descriptions-item label="附件" :span="2">
                  <template v-for="(item2, idx) in asInfo.after_sales_file">
                    <span class="theme-color underline span-file" :key="idx" @click="$fileViewHandle(item2)">
                      {{ item2.file_name }}
                    </span>
                  </template>
                  <span v-if="asInfo.after_sales_file.length == 0">--</span>
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="setp-content" v-if="item.after_sales_status == 40">
              <div class="title">{{ item.content }}</div>
              <el-descriptions :column="2">
                <el-descriptions-item label="现场核实照片" :span="2">
                  <template v-for="(item2, idx) in item.form_data.site_file">
                    <span class="theme-color underline span-file" :key="idx" @click="$fileViewHandle(item2)">
                      {{ item2.file_name }}
                    </span>
                  </template>
                </el-descriptions-item>
                <el-descriptions-item label="是否需集采订货" :span="2">
                  {{ item.form_data.is_order_goods == 1 ? '是' : '否' }}
                </el-descriptions-item>
                <el-descriptions-item label="订货需求（明细）" v-if="item.form_data.is_order_goods == 1" :span="2">
                  {{ item.form_data.order_demand }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="setp-content" v-if="item.after_sales_status == 50">
              <div class="title">{{ item.content }}</div>
              <el-descriptions :column="2">
                <el-descriptions-item label="订货日期" v-if="asInfo.is_order_goods == 1">
                  {{ item.form_data.order_date }}
                </el-descriptions-item>
                <el-descriptions-item label="到货日期" v-if="asInfo.is_order_goods == 1">
                  {{ item.form_data.delivery_date }}
                </el-descriptions-item>
                <el-descriptions-item label="采购专员" v-if="asInfo.is_order_goods == 1">
                  {{ item.form_data.procurement_specialist }}
                </el-descriptions-item>
                <el-descriptions-item label="限期整改时间">{{ item.form_data.deadline_date }}</el-descriptions-item>
                <el-descriptions-item label="责任判定">
                  {{ item.form_data.responsible_party == 1 ? '施工方责任' : item.form_data.responsible_party == 2 ? '供应商责任' :
                  '非施工方&供应商责任' }}
                </el-descriptions-item>
                <el-descriptions-item label="类型划分" :span="asInfo.is_order_goods == 1 ? 1 : 2">
                  {{ problemType(item.form_data.problem_type) }}
                </el-descriptions-item>
                <el-descriptions-item label="物流单号" :span="2" v-if="asInfo.is_order_goods == 1">
                  {{ item.form_data.odd_numbers }}
                </el-descriptions-item>
                <el-descriptions-item label="备注" :span="2">
                  {{ item.form_data.remark ? item.form_data.remark : '--' }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
            <div class="setp-content" v-if="item.after_sales_status == 60">
              <div class="title">工程经理提交施工完成内容</div>
              <el-descriptions :column="2">
                <el-descriptions-item label="现场完成照片" :span="2">
                  <template v-for="(item2, idx) in item.form_data.completion_file">
                    <span class="theme-color underline span-file" :key="idx" @click="$fileViewHandle(item2)">
                      {{ item2.file_name }}
                    </span>
                  </template>
                </el-descriptions-item>
                <el-descriptions-item label="售后时效" :span="2">{{ afterSalesTimeliness }}天</el-descriptions-item>
              </el-descriptions>
            </div>

          </div>
        </el-timeline-item>
      </el-timeline>
    </div>
    <div class="oper-box" v-if="userInfo.position_id == 8 && asInfo.after_sales_status == 20">
      <el-button type="primary" @click="dialogOpen('fpgcjl')">分配工程经理</el-button>
    </div>
    <div class="oper-box" v-if="userInfo.position_id == 7 && asInfo.after_sales_status == 30">
      <el-button type="primary" @click="dialogOpen('xcfkqk')">现场反馈情况</el-button>
    </div>
    <div class="oper-box" v-if="userInfo.position_id == 8 && asInfo.after_sales_status == 40">
      <el-button type="primary" @click="dialogOpen('xqpdtj')">详情判定提交</el-button>
    </div>
    <div class="oper-box" v-if="userInfo.position_id == 7 && asInfo.after_sales_status == 50">
      <el-button type="primary" @click="dialogOpen('zgwctj')">整改完成提交</el-button>
    </div>

    <!-- 分配工程经理 -->
    <el-dialog @close="dialogClose('fpgcjl')" :close-on-click-modal="false" :append-to-body="true" title="分配工程经理"
      :visible.sync="fpgcjlVisible" width="400px">
      <div class="scroll-view">
        <el-form :model="fpgcjlRuleForm" :rules="fpgcjlRules" ref="fpgcjlRuleForm" label-position="left"
          class="form-box">
          <el-form-item label="工程经理" prop="engineering_manager_idx">
            <el-select filterable class="input-box" v-model="fpgcjlRuleForm.engineering_manager_idx" placeholder="请选择工程经理">
              <el-option v-for="(item, idx) in adminList" :key="idx" :label="item.name" :value="idx"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer">
        <el-button type="primary" @click="fpgcjlSubmit('fpgcjlRuleForm')" :loading="fpgcjlRuleForm.subimtLoading">提交</el-button>
        <el-button @click="dialogClose('fpgcjl')">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 现场反馈情况 -->
    <el-dialog @close="dialogClose('xcfkqk')" :close-on-click-modal="false" :append-to-body="true" title="现场反馈情况"
      :visible.sync="xcfkqkVisible" width="600px">
      <div class="scroll-view">
        <el-form :model="xcfkqkRuleForm" :rules="xcfkqkRules" ref="xcfkqkRuleForm" label-position="left">
          <el-form-item label="现场核实照片" prop="site_file">
            <el-upload ref="hsupload" multiple :on-change="xcfkqkChangeFile" :on-remove="xcfkqkFileRemove"
              :auto-upload="false" action="#" accept="image/*,video/*">
              <el-button size="small" icon="el-icon-plus">点击上传</el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label="是否需集采订货" prop="is_order_goods">
            <el-switch v-model="xcfkqkRuleForm.is_order_goods" active-color="#3D7FFF">
            </el-switch>
          </el-form-item>
          <el-form-item label="订货需求(明细)" prop="order_demand" v-if="xcfkqkRuleForm.is_order_goods">
            <el-input :rows="4" class="input-box" v-model="xcfkqkRuleForm.order_demand" type="textarea"
              placeholder="请输入订货需求(明细)"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer">
        <el-button type="primary" @click="xcfkqkSubmit('xcfkqkRuleForm')" :loading="xcfkqkRuleForm.subimtLoading">提交</el-button>
        <el-button @click="dialogClose('xcfkqk')">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 详情判定提交 -->
    <el-dialog @close="dialogClose('xqpdtj')" :close-on-click-modal="false" :append-to-body="true" title="详情判定提交"
      :visible.sync="xqpdtjVisible" width="900px">
      <div class="scroll-view">
        <el-form :model="xqpdtjRuleForm" :rules="xqpdtjRules" ref="xqpdtjRuleForm" label-position="left" inline>
          <el-form-item label="采购专员" prop="procurement_specialist" v-if="asInfo.is_order_goods == 1">
            <el-input class="input-box" v-model="xqpdtjRuleForm.procurement_specialist"
              placeholder="请输入采购专员"></el-input>
          </el-form-item>
          <el-form-item label="物流单号" prop="odd_numbers" v-if="asInfo.is_order_goods == 1">
            <el-input class="input-box" v-model="xqpdtjRuleForm.odd_numbers" placeholder="请输入物流单号"></el-input>
          </el-form-item>
          <el-form-item label="订货日期" prop="order_date" v-if="asInfo.is_order_goods == 1">
            <el-date-picker class="input-box" v-model="xqpdtjRuleForm.order_date" type="date" placeholder="选择订货日期"
              clearable value-format="yyyy-MM-dd" :picker-options="pickerOptionsStart">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="到货日期" prop="delivery_date" v-if="asInfo.is_order_goods == 1">
            <el-date-picker class="input-box" :disabled="!xqpdtjRuleForm.order_date"
              v-model="xqpdtjRuleForm.delivery_date" type="date" placeholder="选择到货日期" clearable
              value-format="yyyy-MM-dd" :picker-options="pickerOptionsStart_">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="类型划分" prop="problem_type">
            <el-select filterable class="input-box" v-model="xqpdtjRuleForm.problem_type" placeholder="请选择类型划分">
              <el-option label="完工未验收" :value="1"></el-option>
              <el-option label="后区仓库" :value="2"></el-option>
              <el-option label="甲供物料" :value="3"></el-option>
              <el-option label="小电器" :value="4"></el-option>
              <el-option label="灯具" :value="5"></el-option>
              <el-option label="胶体脱落" :value="6"></el-option>
              <el-option label="空洞封堵" :value="7"></el-option>
              <el-option label="给排水" :value="8"></el-option>
              <el-option label="漏电（线路）" :value="9"></el-option>
              <el-option label="吊顶补漆" :value="10"></el-option>
              <el-option label="踢脚线脱落" :value="11"></el-option>
              <el-option label="肯德基门" :value="12"></el-option>
              <el-option label="墙板脱落" :value="13"></el-option>
              <el-option label="瓷砖空鼓（破碎）" :value="14"></el-option>
              <el-option label="铝塑板脱落" :value="15"></el-option>
              <el-option label="主体结构" :value="16"></el-option>
              <el-option label="门头漏水" :value="17"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="责任判定" prop="responsible_party">
            <el-select filterable class="input-box" v-model="xqpdtjRuleForm.responsible_party" placeholder="请选择责任判定">
              <el-option label="施工方责任" :value="1"></el-option>
              <el-option label="供应商责任" :value="2"></el-option>
              <el-option label="非施工方&供应商责任" :value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="限期整改时间" prop="deadline_date">
            <el-date-picker class="input-box" v-model="xqpdtjRuleForm.deadline_date" type="date" placeholder="选择限期整改时间"
              clearable value-format="yyyy-MM-dd" :picker-options="pickerOptionsEnd">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="xqpdtjRuleForm.remark" type="textarea" placeholder="请输入备注" autosize></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer">
        <el-button type="primary" @click="xqpdtjSubmit('xqpdtjRuleForm')" :loading="xqpdtjRuleForm.subimtLoading">提交</el-button>
        <el-button @click="dialogClose('xqpdtj')">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 整改完成提交 -->
    <el-dialog @close="dialogClose('zgwctj')" :close-on-click-modal="false" :append-to-body="true" title="现场反馈情况"
      :visible.sync="zgwctjVisible" width="600px">
      <div class="scroll-view">
        <el-form :model="zgwctjRuleForm" :rules="zgwctjRules" ref="zgwctjRuleForm" label-position="left">
          <el-form-item label="现场完工照片" prop="completion_file">
            <el-upload ref="zgupload" multiple :on-change="zgwctjChangeFile" :on-remove="zgwctjFileRemove"
              :auto-upload="false" action="#" accept="image/*">
              <el-button size="small" icon="el-icon-plus">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer">
        <el-button type="primary" @click="zgwctjSubmit('zgwctjRuleForm')" :loading="zgwctjRuleForm.subimtLoading">提交</el-button>
        <el-button @click="dialogClose('zgwctj')">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import asApi from '@/api/afterSalesApi'
import adminApi from "@/api/adminApi";
import { getUserInfo } from '@/utils/auth';

export default {
  name: "",
  props: ['after_sales_id'],
  data() {
    return {
      pickerOptionsStart: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      pickerOptionsEnd: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      pickerOptionsStart_: {},
      userInfo: {},
      asInfo: {},

      // 分配工程经理
      adminList: [],
      fpgcjlRuleForm: {
        engineering_manager_idx: '',
        subimtLoading: false,
      },
      fpgcjlRules: {
        engineering_manager_idx: { required: true, message: "请选择工程经理", trigger: "change" },
      },
      fpgcjlVisible: false,
      // 现场反馈情况
      xcfkqkRuleForm: {
        site_file: [],
        is_order_goods: true,
        order_demand: '',
        subimtLoading: false,
      },
      xcfkqkRules: {
        site_file: { required: true, message: "请上传现场核实照片", trigger: "change" },
        is_order_goods: { required: true, },
        order_demand: { required: true, message: "请输入订货需求(明细)", trigger: "change" }
      },
      xcfkqkVisible: false,
      // 详情判定提交
      xqpdtjRuleForm: {
        order_date: '',
        delivery_date: '',
        deadline_date: '',
        procurement_specialist: '',
        responsible_party: '',
        problem_type: '',
        odd_numbers: '',
        remark: '',
        subimtLoading: false,
      },
      xqpdtjRules: {
        order_date: { required: true, message: "请选择订货日期", trigger: "change" },
        delivery_date: { required: true, message: "请选择到货日期", trigger: "change" },
        deadline_date: { required: true, message: "请选择限期整改时间", trigger: "change" },
        procurement_specialist: { required: true, message: "请输入采购专员", trigger: "change" },
        responsible_party: { required: true, message: "请选择责任判定", trigger: "change" },
        problem_type: { required: true, message: "请选择类型划分", trigger: "change" },
        odd_numbers: { required: true, message: "请输入物流单号", trigger: "change" },
      },
      xqpdtjVisible: false,

      // 整改完成提交
      zgwctjRuleForm: {
        completion_file: [],
        subimtLoading: false,
      },
      zgwctjRules: {
        completion_file: { required: true, message: "请上传现场完成照片", trigger: "change" },
      },
      zgwctjVisible: false,
    }
  },
  watch: {
    'xqpdtjRuleForm.order_date': {
      handler(newValue) {
        this.pickerOptionsStart_ = {
          disabledDate(time) {
            return time.getTime() < new Date(newValue).getTime() - 8.64e7;
          }
        }
        if (newValue > this.xqpdtjRuleForm.delivery_date) {
          this.xqpdtjRuleForm.delivery_date = '';
        }
      },
      // 使用深度监听
      deep: true
    }
  },
  computed: {
    problemType() {
      return type => {
        let res = '';
        switch (type) {
          case 1:
            res = '完工未验收'
            break;
          case 2:
            res = '后区仓库'
            break;
          case 3:
            res = '甲供物料'
            break;
          case 4:
            res = '小电器'
            break;
          case 5:
            res = '灯具'
            break;
          case 6:
            res = '胶体脱落'
            break;
          case 7:
            res = '空洞封堵'
            break;
          case 8:
            res = '给排水'
            break;
          case 9:
            res = '漏电（线路）'
            break;
          case 10:
            res = '吊顶补漆'
            break;
          case 11:
            res = '踢脚线脱落'
            break;
          case 12:
            res = '肯德基门'
            break;
          case 13:
            res = '墙板脱落'
            break;
          case 14:
            res = '瓷砖空鼓（破碎）'
            break;
          case 15:
            res = '铝塑板脱落'
            break;
          case 16:
            res = '主体结构'
            break;
          case 17:
            res = '门头漏水'
            break;
        }
        return res
      }
    },
    afterSalesTimeliness() {
      let asInfo = this.asInfo;
      let date = new Date(asInfo.created_at);
      let year = date.getFullYear();
      let month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
      let day = String(date.getDate()).padStart(2, '0');
      let created_at = `${year}-${month}-${day}`;
      if (asInfo.is_order_goods == 1) {
        let days = this.getDaysDiff(asInfo.order_date, asInfo.delivery_date);
        return this.getDaysDiff(asInfo.completion_date, created_at) - days;
      } else {
        return this.getDaysDiff(asInfo.completion_date, created_at)
      }
    },
  },
  mounted() {
    this.userInfo = getUserInfo();
    // 获取售后详情
    this.getDetails();
  },
  methods: {
    getDetails() {
      asApi.getAfterSalesDetails({
        after_sales_id: this.after_sales_id
      }).then(res => {
        console.log(res, '获取售后详情')
        if (res.code == 200) {
          this.asInfo = res.data;
        }
      })
    },
    getDaysDiff(date1, date2) {
      date1 = new Date(date1);
      date2 = new Date(date2);
      const oneDay = 24 * 60 * 60 * 1000; // 每天的毫秒数
      const date1Ms = date1.getTime(); // 转换第一个日期为时间戳
      const date2Ms = date2.getTime(); // 转换第二个日期为时间戳
      return Math.round((date2Ms - date1Ms) / oneDay);
    },
    dialogOpen(type) {
      switch (type) {
        case "fpgcjl":
          this.getAdminList();
          this.fpgcjlVisible = true;
          break;
        case "xcfkqk":
          this.xcfkqkVisible = true;
          break;
        case 'xqpdtj':
          this.xqpdtjVisible = true;
          break;
        case 'zgwctj':
          this.zgwctjVisible = true;
          break;
      }
    },
    dialogClose(type) {
      switch (type) {
        case "fpgcjl":
          this.fpgcjlRuleForm = this.$options.data().fpgcjlRuleForm;
          this.$nextTick(() => {
            this.$refs["fpgcjlRuleForm"].clearValidate();
            this.fpgcjlVisible = false;
          });
          break;
        case "xcfkqk":
          this.xcfkqkRuleForm = this.$options.data().xcfkqkRuleForm;
          this.$nextTick(() => {
            this.$refs['hsupload'].clearFiles();
            this.$refs["xcfkqkRuleForm"].clearValidate();
            this.xcfkqkVisible = false;
          });
          break;
        case 'xqpdtj':
          this.xqpdtjRuleForm = this.$options.data().xqpdtjRuleForm;
          this.$nextTick(() => {
            this.$refs['xqpdtjRuleForm'].clearValidate();
            this.xqpdtjVisible = false;
          })
          break;
        case 'zgwctj':
          this.zgwctjRuleForm = this.$options.data().zgwctjRuleForm;
          this.$nextTick(() => {
            this.$refs['zgupload'].clearFiles();
            this.$refs['zgwctjRuleForm'].clearValidate();
            this.zgwctjVisible = false;
          })
          break;
      }
    },
    // 分配工程经理
    getAdminList() {
      adminApi.getAdminList({
        page: 1,
        num: 99,
        identity: 2,
        position_id_arr: [7],
      }).then(res => {
        if (res.code == 200) {
          console.log(res, '获取工程经理列表')
          this.adminList = res.data.list;
        }
      })
    },
    fpgcjlSubmit(formName) {
      let fpgcjlRuleForm = this.fpgcjlRuleForm;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.fpgcjlRuleForm.subimtLoading = true;
          asApi.selectEngineeringManager({
            after_sales_id: this.after_sales_id,
            engineering_manager_id: this.adminList[fpgcjlRuleForm.engineering_manager_idx].id,
            engineering_manager_name: this.adminList[fpgcjlRuleForm.engineering_manager_idx].name
          }).then(res => {
            if (res.code == 200) {
              this.getDetails();
              this.dialogClose('fpgcjl');
              if (typeof this.$parent.$parent.getOperList == 'function') {
                this.$parent.$parent.getOperList(3)
              }
            }
            this.fpgcjlRuleForm.subimtLoading = false;
            this.$message({
              type: res.code == 200 ? "success" : "warning",
              message: res.code == 200 ? "操作成功" : res.message,
            });
          })
        }
      })
    },

    // 现场反馈情况
    xcfkqkChangeFile(file, fileList) {
      this.xcfkqkRuleForm.site_file = fileList;
    },
    xcfkqkFileRemove(file, fileList) {
      this.xcfkqkRuleForm.site_file = fileList;
    },
    xcfkqkSubmit(formName) {
      let xcfkqkRuleForm = this.xcfkqkRuleForm;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.xcfkqkRuleForm.subimtLoading = true;
          let obj = {
            after_sales_id: this.after_sales_id,
            is_order_goods: xcfkqkRuleForm.is_order_goods ? 1 : 2,
            order_demand: xcfkqkRuleForm.order_demand,
          }
          let formdata = new FormData();
          formdata.append('data', JSON.stringify(obj))
          xcfkqkRuleForm.site_file.forEach(item => {
            formdata.append('site_file[]', item.raw);
          })
          asApi.feedbackSiteSituation(formdata).then(res => {
            if (res.code == 200) {
              this.getDetails();
              this.dialogClose('xcfkqk');
              if (typeof this.$parent.$parent.getOperList == 'function') {
                this.$parent.$parent.getOperList(3)
              }
            }
            this.xcfkqkRuleForm.subimtLoading = false;
            this.$message({
              type: res.code == 200 ? "success" : "warning",
              message: res.code == 200 ? "操作成功" : res.message,
            });
          })
        }
      })
    },

    // 详情判定提交
    xqpdtjSubmit(formName) {
      let xqpdtjRuleForm = this.xqpdtjRuleForm;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.xqpdtjRuleForm.subimtLoading = true;
          asApi.responsibilityDetermination({
            after_sales_id: this.after_sales_id,
            order_date: xqpdtjRuleForm.order_date,
            delivery_date: xqpdtjRuleForm.delivery_date,
            deadline_date: xqpdtjRuleForm.deadline_date,
            procurement_specialist: xqpdtjRuleForm.procurement_specialist,
            responsible_party: xqpdtjRuleForm.responsible_party,
            problem_type: xqpdtjRuleForm.problem_type,
            odd_numbers: xqpdtjRuleForm.odd_numbers,
            remark: xqpdtjRuleForm.remark,
          }).then(res => {
            if (res.code == 200) {
              this.getDetails();
              this.dialogClose('xqpdtj');
              if (typeof this.$parent.$parent.getOperList == 'function') {
                this.$parent.$parent.getOperList(3)
              }
            }
            this.xqpdtjRuleForm.subimtLoading = false;
            this.$message({
              type: res.code == 200 ? "success" : "warning",
              message: res.code == 200 ? "操作成功" : res.message,
            });
          })
        }
      })
    },

    // 整改完成提交
    zgwctjChangeFile(file, fileList) {
      this.zgwctjRuleForm.completion_file = fileList;
    },
    zgwctjFileRemove(file, fileList) {
      this.zgwctjRuleForm.completion_file = fileList;
    },
    zgwctjSubmit(formName) {
      let zgwctjRuleForm = this.zgwctjRuleForm;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.zgwctjRuleForm.subimtLoading = true;
          let obj = {
            after_sales_id: this.after_sales_id,
          }
          let formdata = new FormData();
          formdata.append('data', JSON.stringify(obj))
          zgwctjRuleForm.completion_file.forEach(item => {
            formdata.append('completion_file[]', item.raw);
          })
          asApi.afterSalesRectification(formdata).then(res => {
            if (res.code == 200) {
              this.getDetails();
              this.dialogClose('zgwctj');
              if (typeof this.$parent.$parent.getOperList == 'function') {
                this.$parent.$parent.getOperList(3)
              }
            }
            this.zgwctjRuleForm.subimtLoading = false;
            this.$message({
              type: res.code == 200 ? "success" : "warning",
              message: res.code == 200 ? "操作成功" : res.message,
            });
          })
        }
      })
    },

  },
};
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>